﻿using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using EPiServer.DataAbstraction;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using EPiServer.Core;
using EPiSugar.UnitTesting;
using EPiSugar.Navigation;
using System;

namespace EPiSugar.Tests.Navigation
{
    [TestFixture]
    public class EnumerationTests : NavigationTestsBase
    {
        [Test]
        public void CanEnumerate_GrandChildren()
        {
            int count = startPage.Children().Children().Count();
            Assert.That(count, Is.EqualTo(9));
        }

        [Test]
        public void CanEnumerate_GrandGrandChildren()
        {
            int count = rootPage.Children().Children().Children().Count();
            Assert.That(count, Is.EqualTo(9));
        }

        [Test]
        public void CanAddChildren_ToEnumeration()
        {
            int count = startPage.Children().Add().Children().Count();
            Assert.That(count, Is.EqualTo(12));
        }

        [Test]
        public void CanEnumerateParents()
        {
            var grandChildren = startPage.Children().Children();
            int count = grandChildren.Parents().Distinct().Count();
            Assert.That(count, Is.EqualTo(3));
        }

        [Test]
        public void CanAddParents_ToEnumeration()
        {
            var grandChildren = startPage.Children().Children();
            int count = grandChildren.Add().Parents().Distinct().Count();
            Assert.That(count, Is.EqualTo(12));
        }

        [Test]
        public void CanEnumerate_Descendants()
        {
            int count = rootPage.Children().Descendants().Count();
            Assert.That(count, Is.EqualTo(12));
        }

        [Test]
        public void CanAddDescendants_ToEnumeration()
        {
            int count = rootPage.Children().Add().Descendants().Count();
            Assert.That(count, Is.EqualTo(14));
        }

        [Test]
        public void CanFilter_ByPageType()
        {
            int count = rootPage.Add().Descendants().Where(Filter.By.PageType(1)).Count();
            Assert.That(count, Is.EqualTo(1));
        }
    }
}